import os
from collections import OrderedDict

from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml import OxmlElement
from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn
from docx.oxml import OxmlElement


def replace_text_header_in_docx(doc, search_text, replace_text):
    """
    功能：word文档中的页眉替换；
    :param doc:
    :param search_text:
    :param replace_text:
    :return:
    """
    # 遍历文档中的所有节（sections）
    for section in doc.sections:
        # 遍历每个节中的页眉
        for paragraph in section.header.paragraphs:
            if search_text in paragraph.text:
                paragraph.text = paragraph.text.replace(search_text, replace_text)
    doc.save(file_path)

# def replace_text_header_in_docx(file_path, search_text, replace_text):
#     # 打开文档
#     doc = Document(file_path)
#
#     # 替换正文中的文本
#     for paragraph in doc.paragraphs:
#         if search_text in paragraph.text:
#             paragraph.text = paragraph.text.replace(search_text, replace_text)
#
#     # 替换页眉中的文本
#     # replace_text_in_header(doc, search_text, replace_text)
#
#     # 保存替换后的文档
#     # doc.save("replaced_" + file_path)
#     doc.save(file_path)

def replace_text_in_docx2(file_path, search_text, replace_text):
    """
    功能（不推荐）（不保持原有格式）：替换word中的文本（包括正文和表格中的文本）；
    问题：不要开启替换表格模块，否则表格中的文本样式会变化（为字体大小小四等）；
    Replace all occurrences of search_text in a docx document with replace_text.

    :param file_path: The path to the docx file.
    :param search_text: The text to search for.
    :param replace_text: The text to replace with.
    """
    # 打开文档
    doc = Document(file_path)
    # 遍历文档中的每个段落（保持原有格式）-可能替换不了
    for paragraph in doc.paragraphs:
        for run in paragraph.runs:
            if search_text in run.text:
                run.text = run.text.replace(search_text, replace_text)

    # 遍历文档中的每个段落（不保持原有格式）-能替换成功
    for paragraph in doc.paragraphs:
        if search_text in paragraph.text:
            paragraph.text = paragraph.text.replace(search_text, replace_text)


    doc.save(file_path)
    print(f"Replaced text in {file_path}")

def replace_text_in_docx(file_path, search_text, replace_text):
    """
    功能（推荐）：替换docx中的正文本文和表格文本（不改变原有字体格式）-

    :param file_path: The path to the docx file.
    :param search_text: The text to search for.
    :param replace_text: The text to replace with.
    """
    # 打开文档
    doc = Document(file_path)

    # 遍历文档中的每个段落
    for paragraph in doc.paragraphs:
        for run in paragraph.runs:
            if search_text in run.text:
                run.text = run.text.replace(search_text, replace_text)

    # 遍历文档中的每个表格-保持原有格式
    for table in doc.tables:
        for row in table.rows:
            for cell in row.cells:
                for paragraph in cell.paragraphs:
                    for run in paragraph.runs:
                        if search_text in run.text:
                            run.text = run.text.replace(search_text, replace_text)

    # 保存替换后的文档
    doc.save(file_path)
    print(f"Replaced text in {file_path}")

def replace_text_by_list_in_docx(file_path, search_text_list, replace_text_list):
    """
    功能（不推荐，单一功能-不能替换页眉）：根据列表依次替换Word文档的文本（.docx替换）-不改变文件名字；

    :param file_path: The path to the docx file.
    :param search_text_list: A list of texts to search for.
    :param replace_text_list: A list of texts to replace with.
    """
    # 打开文档
    doc = Document(file_path)

    # 遍历文档中的每个段落
    for paragraph in doc.paragraphs:
        # 遍历搜索文本和替换文本的列表
        for search_text, replace_text in zip(search_text_list, replace_text_list):
            # 如果段落中包含搜索文本，则进行替换
            if search_text in paragraph.text:
                paragraph.text = paragraph.text.replace(search_text, replace_text)

    # 保存替换后的文档
    doc.save(file_path)
    print(f"Replaced text in {file_path}")

def replace_text_header_by_list_in_docx(file_path, search_text_list, replace_text_list):
    """
    功能（推荐）：替换文本并保持页眉分散对齐-根据列表依次替换Word文档的文本(包括替换正文文本、替换页眉，页眉分散对齐)（.docx替换）-不改变文件名字；
    特点：（1）按列表顺序依次替换；（2）保留原文本的所有格式，包括字体大小、粗体等格式；
    参数：
        :param file_path: The path to the docx file.
        :param search_text_list: [],A list of texts to search for.
        :param replace_text_list: [],A list of texts to replace with.
    调用：
        file_path = 'D:/天星科技发展有限公司/项目相关文档/上传文档-贵安/替换测试/AI数字人_功能测试报告.docx'
        search_text_list =["北京捷通华声科技股份有限公司"]# ["天津市灵算人工智能公共数据平台有限公司"]
        replace_text_list = ["天津市灵算人工智能公共数据平台有限公司"]#["北京捷通华声科技股份有限公司"]
        replace_text_header_by_list_in_docx(file_path, search_text_list, replace_text_list)
    """
    # 打开文档
    doc = Document(file_path)
    #1.替换页眉文本
    for section in doc.sections:
        # 遍历每个节中的页眉
        for paragraph in section.header.paragraphs:
            # 在run级别替换页眉文本以保留格式
            for run in paragraph.runs:
                for search_text, replace_text in zip(search_text_list, replace_text_list):
                    if search_text in run.text:
                        run.text = run.text.replace(search_text, replace_text)
            # 2.设置页眉对齐方式为分散对齐
            paragraph.alignment = WD_ALIGN_PARAGRAPH.DISTRIBUTE

    # 3.替换正文的文本（保持格式）
    for paragraph in doc.paragraphs:
        for run in paragraph.runs:
            for search_text, replace_text in zip(search_text_list, replace_text_list):
                if search_text in run.text:
                    run.text = run.text.replace(search_text, replace_text)

    # 4.替换表格中的文本（保持原有格式）
    for table in doc.tables:
        for row in table.rows:
            for cell in row.cells:
                for paragraph in cell.paragraphs:
                    for run in paragraph.runs:
                        for search_text, replace_text in zip(search_text_list, replace_text_list):
                            if search_text in run.text:
                                run.text = run.text.replace(search_text, replace_text)

    # 保存替换后的文档
    doc.save(file_path)
    print(f"Replaced text in {file_path} with format preserved")

def replace_text_header_by_list_in_docx_folder_backup(folder_path, search_text_list, replace_text_list):
    """
    功能(推荐)：文件夹：递归替换文件夹下所有Word文档的文本(包括替换正文文本、替换表格内容、替换页眉，页眉分散对齐)（.docx替换）-不改变文件名字；
    特点：（1）按列表顺序依次替换；(2)替换列表中：建议一次只替换一个内容；（3）保留原文本的所有格式，包括字体大小、粗体等格式；
    参数：
        :param file_path: The path to the docx file.
        :param search_text_list（建议有交叉的只放一个内容）: [],A list of texts to search for.
        :param replace_text_list（建议有交叉的只放一个内容）: [],A list of texts to replace with.
    调用：
        folder_path = 'D:/天星科技发展有限公司/项目相关文档/上传文档-贵安/替换测试'
        search_text_list =["北京捷通华声科技股份有限公司"]# ["天津市灵算人工智能公共数据平台有限公司"]
        replace_text_list = ["天津市灵算人工智能公共数据平台有限公司"]#["北京捷通华声科技股份有限公司"]
        replace_text_header_by_list_in_docx_folder(folder_path, search_text_list, replace_text_list)
    """
    file_list=find_folder_docx_files(folder_path)
    for absolute_file_path in file_list:
        replace_text_header_by_list_in_docx(absolute_file_path, search_text_list, replace_text_list)

def replace_text_header_by_list_in_docx_folder(folder_path, search_text_list, replace_text_list):
    """
    功能(推荐)：文件夹：递归替换文件夹下所有Word文档的文本(包括替换正文文本、替换表格内容、替换页眉，页眉分散对齐)（.docx替换）-不改变文件名字；
    特点：（1）按列表顺序依次替换；(2)替换列表中：建议一次只替换一个内容；（3）保留原文本的所有格式，包括字体大小、粗体等格式；
    参数：
        :param file_path: The path to the docx file.
        :param search_text_list（建议有交叉的只放一个内容）: [],A list of texts to search for.
        :param replace_text_list（建议有交叉的只放一个内容）: [],A list of texts to replace with.
    调用：
        folder_path = 'D:/天星科技发展有限公司/项目相关文档/上传文档-贵安/替换测试'
        search_text_list =["北京捷通华声科技股份有限公司"]# ["天津市灵算人工智能公共数据平台有限公司"]
        replace_text_list = ["天津市灵算人工智能公共数据平台有限公司"]#["北京捷通华声科技股份有限公司"]
        replace_text_header_by_list_in_docx_folder(folder_path, search_text_list, replace_text_list)
    """
    file_list=find_folder_docx_files(folder_path)
    for absolute_file_path in file_list:
        replace_text_header_by_list_in_docx(absolute_file_path, search_text_list, replace_text_list)


def replace_text_in_folder(folder_path, search_text, replace_text):
    """
    功能：（推荐）递归替换文件夹下所有Word文档的文本（包括正文和页眉）（.docx替换）-不改变文件名字；
    """
    file_list=find_folder_docx_files(folder_path)
    for absolute_file_path in file_list:
        replace_text_in_docx(absolute_file_path, search_text, replace_text)
        replace_text_header_in_docx(absolute_file_path, search_text, replace_text)


def replace_text_in_folder2(folder_path, search_text, replace_text):
    """
    功能：递归替换文件夹下所有Word文档的文本（.docx替换）-不改变文件名字
    """
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.endswith(".docx") and not file.startswith("~$"):#不处理临时文本
                file_path = os.path.join(root, file)
                absolute_file_path = os.path.abspath(file_path)
                print(f"Processing file: {absolute_file_path}")
                replace_text_in_docx(absolute_file_path, search_text, replace_text)
                replace_text_header_in_docx(absolute_file_path, search_text, replace_text)

def change_header_to_justified(filename):
    """
    打开现有文档并将页眉格式更改为分散对齐。
    :param filename: 要打开的文档文件名
    """
    # 打开文档
    doc = Document(filename)

    for section in doc.sections:
        header = section.header
        for paragraph in header.paragraphs:
            paragraph.alignment = WD_ALIGN_PARAGRAPH.DISTRIBUTE
    # 保存文档
    doc.save(filename)
    print(f"Updated header alignment in {filename}")

#
def find_folder_docx_files(directory):
    """
    功能：遍历目录：将所有.docx文件绝对路径-》list
    调用：
        file_list=find_folder_docx_files(folder_path)
        print(file_list)
    :param directory:
    :return:
    """
    docx_files = []
    # 使用os.walk遍历目录
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.docx') and not file.startswith("~$"):
                # 使用os.path.join获取文件的绝对路径
                docx_files.append(os.path.join(root, file))
    return docx_files


def change_header_to_justified_folder(folder_path):
    """
    遍历目录的模板；
    功能：目录下所有.docx文件的页眉格式更改为分散对齐
    :param folder_path: 目录的路径
    """
    docx_files = find_folder_docx_files(folder_path)
    for docx_file in docx_files:
        change_header_to_justified(docx_file)


def replace_text_with_format_preserved(doc, search_text, replace_text):
    """
    功能：替换文档中的文本，同时保留原始格式。
    核心改进：能够处理跨多个run的文本替换，并添加部分匹配功能
    
    :param doc: Document对象
    :param search_text: 要搜索的文本
    :param replace_text: 替换的文本
    """
    replacements_made = 0
    
    # 处理正文段落
    for paragraph in doc.paragraphs:
        # 分别存储所有runs的文本和对象
        text_runs = [(run.text, run) for run in paragraph.runs]
        # 合并所有text_runs的text，形成段落的完整文本
        paragraph_text = "".join([text for text, _ in text_runs])
        
        # 尝试大小写不敏感的匹配
        if search_text.lower() in paragraph_text.lower():
            # 定位搜索文本在段落中的位置
            start_pos = paragraph_text.lower().find(search_text.lower())
            actual_text = paragraph_text[start_pos:start_pos+len(search_text)]
            
            # 找出包含搜索文本起始部分的run
            current_pos = 0
            start_run_index = None
            for i, (text, _) in enumerate(text_runs):
                if start_pos >= current_pos and start_pos < current_pos + len(text):
                    start_run_index = i
                    break
                current_pos += len(text)
            
            if start_run_index is not None:
                # 如果搜索文本完全包含在一个run中
                current_run_text = text_runs[start_run_index][0]
                relative_start = start_pos - current_pos
                
                if relative_start + len(search_text) <= len(current_run_text):
                    # 完全在一个run中，直接替换
                    new_text = current_run_text[:relative_start] + replace_text + current_run_text[relative_start+len(search_text):]
                    text_runs[start_run_index][1].text = new_text
                    replacements_made += 1
                else:
                    # 跨多个run，将整个替换文本放在第一个run中
                    prefix = current_run_text[:relative_start]
                    text_runs[start_run_index][1].text = prefix + replace_text
                    
                    # 计算需要清空的后续run的数量
                    remaining_text_length = len(search_text) - (len(current_run_text) - relative_start)
                    current_length = 0
                    runs_to_clear = []
                    
                    for j in range(start_run_index + 1, len(text_runs)):
                        runs_to_clear.append(j)
                        current_length += len(text_runs[j][0])
                        if current_length >= remaining_text_length:
                            # 找到了足够的run来覆盖搜索文本
                            last_run = text_runs[j]
                            excess = current_length - remaining_text_length
                            if excess > 0:
                                # 保留最后一个run的尾部文本
                                text_runs[j][1].text = last_run[0][-excess:]
                            else:
                                text_runs[j][1].text = ""
                            break
                    
                    # 清空中间的run
                    for j in runs_to_clear[:-1]:
                        text_runs[j][1].text = ""
                    
                    replacements_made += 1

    # 处理表格
    for table in doc.tables:
        for row in table.rows:
            for cell in row.cells:
                for paragraph in cell.paragraphs:
                    # 分别存储所有runs的文本和对象
                    text_runs = [(run.text, run) for run in paragraph.runs]
                    # 合并所有text_runs的text，形成段落的完整文本
                    paragraph_text = "".join([text for text, _ in text_runs])
                    
                    # 尝试大小写不敏感的匹配
                    if search_text.lower() in paragraph_text.lower():
                        # 定位搜索文本在段落中的位置
                        start_pos = paragraph_text.lower().find(search_text.lower())
                        actual_text = paragraph_text[start_pos:start_pos+len(search_text)]
                        
                        # 找出包含搜索文本起始部分的run
                        current_pos = 0
                        start_run_index = None
                        for i, (text, _) in enumerate(text_runs):
                            if start_pos >= current_pos and start_pos < current_pos + len(text):
                                start_run_index = i
                                break
                            current_pos += len(text)
                        
                        if start_run_index is not None:
                            # 类似上面的逻辑处理表格中的替换
                            current_run_text = text_runs[start_run_index][0]
                            relative_start = start_pos - current_pos
                            
                            if relative_start + len(search_text) <= len(current_run_text):
                                new_text = current_run_text[:relative_start] + replace_text + current_run_text[relative_start+len(search_text):]
                                text_runs[start_run_index][1].text = new_text
                                replacements_made += 1
                            else:
                                # 跨多个run的处理
                                prefix = current_run_text[:relative_start]
                                text_runs[start_run_index][1].text = prefix + replace_text
                                
                                remaining_text_length = len(search_text) - (len(current_run_text) - relative_start)
                                current_length = 0
                                runs_to_clear = []
                                
                                for j in range(start_run_index + 1, len(text_runs)):
                                    runs_to_clear.append(j)
                                    current_length += len(text_runs[j][0])
                                    if current_length >= remaining_text_length:
                                        last_run = text_runs[j]
                                        excess = current_length - remaining_text_length
                                        if excess > 0:
                                            text_runs[j][1].text = last_run[0][-excess:]
                                        else:
                                            text_runs[j][1].text = ""
                                        break
                                
                                for j in runs_to_clear[:-1]:
                                    text_runs[j][1].text = ""
                                
                                replacements_made += 1

    # 处理页眉
    for section in doc.sections:
        header = section.header
        for paragraph in header.paragraphs:
            # 分别存储所有runs的文本和对象
            text_runs = [(run.text, run) for run in paragraph.runs]
            # 合并所有text_runs的text，形成段落的完整文本
            paragraph_text = "".join([text for text, _ in text_runs])
            
            # 尝试大小写不敏感的匹配
            if search_text.lower() in paragraph_text.lower():
                # 定位搜索文本在段落中的位置
                start_pos = paragraph_text.lower().find(search_text.lower())
                actual_text = paragraph_text[start_pos:start_pos+len(search_text)]
                
                # 找出包含搜索文本起始部分的run
                current_pos = 0
                start_run_index = None
                for i, (text, _) in enumerate(text_runs):
                    if start_pos >= current_pos and start_pos < current_pos + len(text):
                        start_run_index = i
                        break
                    current_pos += len(text)
                
                if start_run_index is not None:
                    # 类似上面的逻辑处理页眉中的替换
                    current_run_text = text_runs[start_run_index][0]
                    relative_start = start_pos - current_pos
                    
                    if relative_start + len(search_text) <= len(current_run_text):
                        new_text = current_run_text[:relative_start] + replace_text + current_run_text[relative_start+len(search_text):]
                        text_runs[start_run_index][1].text = new_text
                        replacements_made += 1
                    else:
                        # 跨多个run的处理
                        prefix = current_run_text[:relative_start]
                        text_runs[start_run_index][1].text = prefix + replace_text
                        
                        remaining_text_length = len(search_text) - (len(current_run_text) - relative_start)
                        current_length = 0
                        runs_to_clear = []
                        
                        for j in range(start_run_index + 1, len(text_runs)):
                            runs_to_clear.append(j)
                            current_length += len(text_runs[j][0])
                            if current_length >= remaining_text_length:
                                last_run = text_runs[j]
                                excess = current_length - remaining_text_length
                                if excess > 0:
                                    text_runs[j][1].text = last_run[0][-excess:]
                                else:
                                    text_runs[j][1].text = ""
                                break
                        
                        for j in runs_to_clear[:-1]:
                            text_runs[j][1].text = ""
                        
                        replacements_made += 1
                
                # 设置页眉对齐方式为分散对齐
                paragraph.alignment = WD_ALIGN_PARAGRAPH.DISTRIBUTE
    
    return replacements_made

def replace_text_header_by_list_in_docx_advanced(file_path, search_text_list, replace_text_list):
    """
    功能（推荐）：增强版 - 替换文本并保持原格式和页眉分散对齐
    特点：（1）按列表顺序依次替换；（2）完全保留原文本的所有格式，包括字体大小、粗体等格式；
         （3）可以处理跨多个run的文本替换场景；（4）替换内容完全准确。
    
    :param file_path: The path to the docx file.
    :param search_text_list: [],A list of texts to search for.
    :param replace_text_list: [],A list of texts to replace with.
    调用：
        file_path = 'D:/项目文档/测试/示例文档.docx'
        search_text_list =["北京捷通华声科技股份有限公司"]
        replace_text_list = ["天津市灵算人工智能公共数据平台有限公司"]
        replace_text_header_by_list_in_docx_advanced(file_path, search_text_list, replace_text_list)
    """
    try:
        # 打开文档
        doc = Document(file_path)
        
        total_replacements = 0
        # 按列表依次替换文本
        for search_text, replace_text in zip(search_text_list, replace_text_list):
            replacements = replace_text_with_format_preserved(doc, search_text, replace_text)
            total_replacements += replacements
        
        # 保存替换后的文档
        doc.save(file_path)
        
        if total_replacements > 0:
            print(f"文件: {os.path.basename(file_path)}, 替换次数: {total_replacements}")
        
        return total_replacements
    except Exception as e:
        print(f"处理文件 {os.path.basename(file_path)} 时出错: {str(e)}")
        return 0

def replace_text_with_filename_change_folder(folder_path, search_text_list, replace_text_list, rename_files=False, replace_content=True):
    """
    功能：批量替换文件夹中所有docx文件的内容和文件名
    特点：（1）递归处理子文件夹；（2）可单独控制文件内容和文件名替换；（3）保留原格式
    
    :param folder_path: 文件夹路径
    :param search_text_list: 要搜索的文本列表
    :param replace_text_list: 要替换的文本列表
    :param rename_files: 是否同时重命名文件，默认为False
    :param replace_content: 是否替换文件内容，默认为True
    :return: 处理的文件数量
    """
    file_list = find_folder_docx_files(folder_path)
    processed_count = 0
    replaced_count = 0
    
    print(f"\n开始处理文件夹: {folder_path}")
    print(f"搜索文本: {search_text_list}")
    print(f"替换文本: {replace_text_list}")
    print(f"{'替换内容' if replace_content else '不替换内容'}, {'重命名文件' if rename_files else '不重命名文件'}")
    print(f"找到 {len(file_list)} 个文件待处理...")
    
    for absolute_file_path in file_list:
        try:
            file_replaced = False
            # 替换内容
            if replace_content:
                replacements = replace_text_header_by_list_in_docx_advanced(absolute_file_path, search_text_list, replace_text_list)
                if replacements > 0:
                    replaced_count += 1
                    file_replaced = True
            
            # 替换文件名
            if rename_files:
                new_path = replace_text_with_filename_change(absolute_file_path, search_text_list, replace_text_list, True, False)
                if new_path != absolute_file_path:  # 文件名有变化
                    if not file_replaced:  # 内容没变但文件名变了
                        replaced_count += 1
                    print(f"文件已重命名: {os.path.basename(absolute_file_path)} -> {os.path.basename(new_path)}")
            
            processed_count += 1
        except Exception as e:
            print(f"处理文件 {os.path.basename(absolute_file_path)} 时出错: {str(e)}")
    
    print(f"\n处理完成! 总共处理 {processed_count} 个文件, 其中 {replaced_count} 个文件有替换")
    return processed_count


def replace_text_with_filename_change(file_path, search_text_list, replace_text_list, rename_file=True, replace_content=True):
    """
    功能：替换文档内容的同时更改文件名
    特点：（1）使用增强的替换方法保留原格式；（2）同时替换文件名中包含的搜索文本
    参数控制：可以分别控制是否替换内容和是否重命名文件
    
    :param file_path: 文件路径
    :param search_text_list: 要搜索的文本列表
    :param replace_text_list: 要替换的文本列表
    :param rename_file: 是否同时重命名文件，默认为True
    :param replace_content: 是否替换文件内容，默认为True
    :return: 新的文件路径（如果更改了文件名）
    """
    # 先替换文档内容(如果需要)
    if replace_content:
        replace_text_header_by_list_in_docx_advanced(file_path, search_text_list, replace_text_list)
    
    # 如果不需要替换文件名，直接返回
    if not rename_file:
        return file_path
    
    # 分离文件路径和文件名
    file_dir = os.path.dirname(file_path)
    file_name = os.path.basename(file_path)
    file_name_without_ext, ext = os.path.splitext(file_name)
    
    # 替换文件名中的文本
    new_file_name = file_name_without_ext
    for search_text, replace_text in zip(search_text_list, replace_text_list):
        if search_text in new_file_name:
            new_file_name = new_file_name.replace(search_text, replace_text)
    
    # 如果文件名有变化，进行重命名
    if new_file_name != file_name_without_ext:
        new_file_path = os.path.join(file_dir, new_file_name + ext)
        # 确保新文件名不存在
        if os.path.exists(new_file_path):
            base_name = new_file_name
            counter = 1
            while os.path.exists(os.path.join(file_dir, f"{base_name}_{counter}{ext}")):
                counter += 1
            new_file_path = os.path.join(file_dir, f"{base_name}_{counter}{ext}")
        
        try:
            os.rename(file_path, new_file_path)
            return new_file_path
        except Exception as e:
            print(f"重命名文件时出错: {str(e)}")
            return file_path
    
    return file_path

def guizhou_replace():
    """
    功能：贵安项目所有文档的文本替换与对齐；
    :return:
    """
    print("开始替换文本...")

    # a.202504专著替换
    ## a.1 内容替换（同时替换文件名）
    folder_path = "D:/天星科技发展有限公司/2025软著申请-10个平台-资料汇总/文档资料/智算中心资源管理平台"
    
    # 使用更精确的搜索文本，确保能匹配到文档中的实际内容
    search_text_list = ["智算运维平台"]
    replace_text_list = ["智算中心资源管理平台"]
    
    ## 仅替换文件内容，不替换文件名
    # replace_text_with_filename_change_folder(folder_path, search_text_list, replace_text_list, rename_files=False, replace_content=True)
    
    ## 都替换
    replace_text_with_filename_change_folder(folder_path, search_text_list, replace_text_list, rename_files=True, replace_content=True)
    
    ## 仅替换文件名，不替换内容
    # replace_text_with_filename_change_folder(folder_path, search_text_list, replace_text_list, rename_files=True, replace_content=False)
    # replace_text_with_filename_change_folder(folder_path, search_text_list, replace_text_list, rename_files=False, replace_content=True)
    
    print("替换操作完成!")
    
    
if __name__ == '__main__':
    # 调用贵安项目替换函数
    print("开始替换...")
    guizhou_replace()






